<?php
namespace Management\Model;
use Think\Model;
class UserLogDetailModel extends Model {

	    protected $auth_key = 'pangu_dd_on_board'; 

	
		
		
		
		public function save( $user_id , $username_once , $table_name , $section_name , $section_id)
		{
				$user_id = intval( $user_id );

				
				$detail = array(
						"user_id" => $user_id,
						"username_once" => $username_once,
						"table_name" => $table_name,
						"section_name" => $section_name,
						"section_id" => $section_id,
						"is_builder" => $_COOKIE['BUILDER_LOGIN']?1:0,
						"addtime" => time( ),
                        "ip"=>getIP()
				) ;
				$this->add( $detail);


				
		 }

		public function auth( )
		{
				$authSuc = FALSE;
				if ( cookie( "AUTH_MEMBER_STRING") ){
						$authInfo = $this->getAuthInfo( );
						$map['id'] = $authInfo['member_id'];
						$map['password'] = $authInfo['member_pass'];
						
						$userInfo = $this->where($map)->find();
						if ( $userInfo['id'] )$authSuc = TRUE;
				}
				
				if(!$authSuc){
					cookie( "AUTH_MEMBER_STRING", null );
					cookie( "AUTH_MEMBER_NAME", null );
					cookie( "AUTH_MEMBER_REALNAME", null );
				}
				
				
				
				return $authSuc;
		}	
		
		public function modify( $postInfo )
		{
				$authInfo = $this->getAuthInfo( );
				$updateInfo = array(
						"id" => $authInfo['member_id'],
						"nickname" => $postInfo['nickname'],
						"mobile" => $postInfo['mobile'],
						"email" => $postInfo['email'],
						"avatar" => $postInfo['avatar'],
				);
				try
				{
						$this->save( $updateInfo);
						cookie( "AUTH_MEMBER_REALNAME", $info['nickname'] );
						return 1;
				}
				catch ( Exception $e )
				{
						return 0;
				}
		}		
		
		
		
		
		
		
		
		
		public function editPassword( $pwd )
		{
				$authInfo = $this->getAuthInfo( );
				$memberId = $authInfo['member_id'];
				
				if ( $memberId && $pwd )
				{
					$data['id'] = $memberId;
					$data['password'] = md5($pwd);
					$this->save($data); // 根据条件更新记录				
					return true;
				}else{
					return false;
				}
		}		
		
		
		
		

}
